package com.ysy.logistics.entities.stock;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.ysy.common.entities.BaseEntity;
import com.ysy.logistics.entities.supplier.SupGoods;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;

import java.util.List;

/**
 * @ClassDescription: 商品容量\入库规格
 * @Author:姚斯羽
 * @Create:2025/3/30 22:47
 **/
@Data
@Schema(name = "GoodsCapacity", description = "商品容量表")
@TableName(value = "goods_capacity",autoResultMap = true)
public class GoodsCapacity extends BaseEntity {

    @Schema(description = "id")
    @TableId(value = "id", type = IdType.ASSIGN_UUID)
    private String id;

    @Schema(description = "商品名称")
    @TableField(value = "goods_name")
    @NotBlank(message = "商品名称不能为空")
    private String goodsName;

    @Schema(description = "商品类型")
    @TableField(value = "goods_type")
    @NotBlank(message = "商品类型不能为空")
    private String goodsType;

    @Schema(description = "单价")
    @TableField(value = "price")
    @Min(value = 1,message = "单价不能小于1")
    private Integer price;

    @Schema(description = "计量单位")
    @TableField(value = "price_unit")
    @NotBlank(message = "计量单位不能为空")
    private String priceUnit;

    @Schema(description = "规格")
    @TableField(value = "specification",typeHandler = JacksonTypeHandler.class)
    private List<String> specification;

    @Schema(description = "单位容量")
    @TableField(value = "capacity")
    @Min(value = 1,message = "单位容量不能小于1")
    private Integer capacity;

    /**
     * 将供应商商品转化为商品容量
     * @param goods
     * @return
     */
    public static GoodsCapacity supGoodsToCapacity(SupGoods goods){
        GoodsCapacity goodsCapacity = new GoodsCapacity();
        goodsCapacity.setGoodsName(goods.getName());
        goodsCapacity.setGoodsType(goods.getType());
        goodsCapacity.setPrice(goods.getPrice());
        goodsCapacity.setPriceUnit(goods.getPriceUnit());
        goodsCapacity.setSpecification(goods.getSpecification());
        return goodsCapacity;
    }
}
